﻿using System;
using System.Collections.Generic;
using StockTrader.DAL.IDAL;
using StockTrader.DAL.Factory;
using StockTrader.BusinessService.DataContract;
using StockTrader.FrontEnd.DataContract;
using StockTrader.FrontEnd.OrderTracker.Business;
using StockTrader.BusinessService.DataContract.Structure;
using StockTrader.BusinessService.DataContract.Hastc;

namespace StockTrader.FrontEnd.OrderTracker.DAL
{
    public class DALclient
    {
        IHoseOrders dalOrders;
        IStsStocks dalHastc;

        public List<OrderNewData> getNewConditionedOrderData()
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getNewConditionedOrderData();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<OrderChangeData> getOrderChangeData()
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getOrderChangeData();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<OrderCancelData> getOrderCancelData()
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getOrderCancelData();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalOrders.Close();
            }
        }


        public List<ConfirmOrderChangeData> getConfirmOrderChangeData()
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getConfirmOrderChangeData();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<ConfirmCrossingDealData> getConfirmCrossingDealData()
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getConfirmCrossingDealData();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<ConfirmDealData> getConfirmDealData()
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getConfirmDealData();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<ConfirmOrderCancelData> getConfirmOrderCancelData()
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getConfirmOrderCancelData();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<ConfirmOrderNewData> getConfirmOrderNewData()
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getConfirmOrderNewData();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalOrders.Close();
            }
        }


        public List<OFPTDealData> getOFPTDealData()
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getOFPTDealData();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<TFPTDealData> getTFPTDealData()
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getTFPTDealData();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<OrderPtCancelRequestData> getOrderPtCancelRequest()
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getOrderPtCancelRequest();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<ConfirmPtDealData> getConfirmPtDealData()
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getConfirmPtDealData();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<ConfirmPtDealCancelData> getConfirmPtDealCancelData()
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getConfirmPtDealCancelData();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<PtACKData> getPtACKData()
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getPtACKData();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<PtDealReplyData> getPtDealReplyData()
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getPtDealReplyData();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOrders.Close();
            }
        }


        public List<STSORDERS> getSTS_ORDERS()
        {
            dalHastc = StockTrader.DAL.Factory.StsStocksFactory.Create(Parameters.DBType);
            try
            {
                dalHastc.Open(Parameters.CNN);
                return dalHastc.getSTS_ORDERS();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalHastc.Close();
            }
        }
        public List<STSTRADING_RESULT> getSTS_TRADING_RESULT()
        {
            dalHastc = StockTrader.DAL.Factory.StsStocksFactory.Create(Parameters.DBType);
            try
            {
                dalHastc.Open(Parameters.CNN);
                return dalHastc.getSTS_TRADING_RESULT();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalHastc.Close();
            }
        }
        public List<SecuritiesInfo> getSTOCKSINFO()
        {
            dalHastc = StockTrader.DAL.Factory.StsStocksFactory.Create(Parameters.DBType);
            try
            {
                dalHastc.Open(Parameters.CNN);
                return dalHastc.getSTOCKSINFO();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalHastc.Close();
            }
        }
        public List<STSTOP3_PRICE_A> getSTS_TOP3_PRICE_A()
        {
            dalHastc = StockTrader.DAL.Factory.StsStocksFactory.Create(Parameters.DBType);
            try
            {
                dalHastc.Open(Parameters.CNN);
                return dalHastc.getSTS_TOP3_PRICE_A();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalHastc.Close();
            }
        }
        public List<STSTOP3_PRICE_B> getSTS_TOP3_PRICE_B()
        {
            dalHastc = StockTrader.DAL.Factory.StsStocksFactory.Create(Parameters.DBType);
            try
            {
                dalHastc.Open(Parameters.CNN);
                return dalHastc.getSTS_TOP3_PRICE_B();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalHastc.Close();
            }
        }
        public List<STSMARKETINFO> getSTS_MARKETINFO()
        {
            dalHastc = StockTrader.DAL.Factory.StsStocksFactory.Create(Parameters.DBType);
            try
            {
                dalHastc.Open(Parameters.CNN);
                return dalHastc.getSTS_MARKETINFO();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalHastc.Close();
            }
        }




        public List<OrderNewData> getBackupNewConditionedOrderData(DateTime from, DateTime to)
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getBackupNewConditionedOrderData( from,  to);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<OrderChangeData> getBackupOrderChangeData(DateTime from, DateTime to)
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getBackupOrderChangeData( from,  to);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<OrderCancelData> getBackupOrderCancelData(DateTime from, DateTime to)
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getBackupOrderCancelData( from,  to);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalOrders.Close();
            }
        }


        public List<ConfirmOrderChangeData> getBackupConfirmOrderChangeData(DateTime from, DateTime to)
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getBackupConfirmOrderChangeData( from,  to);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<ConfirmCrossingDealData> getBackupConfirmCrossingDealData(DateTime from, DateTime to)
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getBackupConfirmCrossingDealData( from,  to);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<ConfirmDealData> getBackupConfirmDealData(DateTime from, DateTime to)
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getBackupConfirmDealData( from,  to);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<ConfirmOrderCancelData> getBackupConfirmOrderCancelData(DateTime from, DateTime to)
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getBackupConfirmOrderCancelData(from, to);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<ConfirmOrderNewData> getBackupConfirmOrderNewData(DateTime from, DateTime to)
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getBackupConfirmOrderNewData( from,  to);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalOrders.Close();
            }
        }


        public List<OFPTDealData> getBackupOFPTDealData(DateTime from, DateTime to)
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getBackupOFPTDealData( from,  to);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<TFPTDealData> getBackupTFPTDealData(DateTime from, DateTime to)
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getBackupTFPTDealData( from,  to);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<OrderPtCancelRequestData> getBackupOrderPtCancelRequest(DateTime from, DateTime to)
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getBackupOrderPtCancelRequest( from,  to);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<ConfirmPtDealData> getBackupConfirmPtDealData(DateTime from, DateTime to)
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getBackupConfirmPtDealData( from,  to);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<ConfirmPtDealCancelData> getBackupConfirmPtDealCancelData(DateTime from, DateTime to)
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getBackupConfirmPtDealCancelData( from,  to);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<PtACKData> getBackupPtACKData(DateTime from, DateTime to)
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getBackupPtACKData( from,  to);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOrders.Close();
            }
        }
        public List<PtDealReplyData> getBackupPtDealReplyData(DateTime from, DateTime to)
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getBackupPtDealReplyData( from,  to);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOrders.Close();
            }
        }


        public List<STSORDERS> getSTS_ORDERSBackup(DateTime from, DateTime to)
        {
            dalHastc = StockTrader.DAL.Factory.StsStocksFactory.Create(Parameters.DBType);
            try
            {
                dalHastc.Open(Parameters.CNN);
                return dalHastc.getSTS_ORDERSBackup( from,  to);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalHastc.Close();
            }
        }
        public List<STSTRADING_RESULT> getSTS_TRADING_RESULTBackup(DateTime from, DateTime to)
        {
            dalHastc = StockTrader.DAL.Factory.StsStocksFactory.Create(Parameters.DBType);
            try
            {
                dalHastc.Open(Parameters.CNN);
                return dalHastc.getSTS_TRADING_RESULTBackup( from,  to);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalHastc.Close();
            }
        }
        public List<SecuritiesInfo> getSTOCKSINFOBackup(DateTime from, DateTime to)
        {
            dalHastc = StockTrader.DAL.Factory.StsStocksFactory.Create(Parameters.DBType);
            try
            {
                dalHastc.Open(Parameters.CNN);
                return dalHastc.getSTOCKSINFOBackup( from,  to);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalHastc.Close();
            }
        }
        public List<STSTOP3_PRICE_A> getSTS_TOP3_PRICE_ABackup(DateTime from, DateTime to)
        {
            dalHastc = StockTrader.DAL.Factory.StsStocksFactory.Create(Parameters.DBType);
            try
            {
                dalHastc.Open(Parameters.CNN);
                return dalHastc.getSTS_TOP3_PRICE_ABackup( from,  to);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalHastc.Close();
            }
        }
        public List<STSTOP3_PRICE_B> getSTS_TOP3_PRICE_BBackup(DateTime from, DateTime to)
        {
            dalHastc = StockTrader.DAL.Factory.StsStocksFactory.Create(Parameters.DBType);
            try
            {
                dalHastc.Open(Parameters.CNN);
                return dalHastc.getSTS_TOP3_PRICE_BBackup( from,  to);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalHastc.Close();
            }
        }
        public List<STSMARKETINFO> getSTS_MARKETINFOBackup(DateTime from, DateTime to)
        {
            dalHastc = StockTrader.DAL.Factory.StsStocksFactory.Create(Parameters.DBType);
            try
            {
                dalHastc.Open(Parameters.CNN);
                return dalHastc.getSTS_MARKETINFOBackup( from,  to);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalHastc.Close();
            }
        }

        public List<string> getVipAccount()
        {
            dalOrders = StockTrader.DAL.Factory.HoseOrdersFactory.Create(Parameters.DBType);
            try
            {
                dalOrders.Open(Parameters.CNN);
                return dalOrders.getVipAccount();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOrders.Close();
            }
        }
    }
}
